﻿using Dapper;
using Domain.Entity;
using Domain.Repository;
using Microsoft.Data.SqlClient;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EFCore.Repository
{
	public class SSDRepository : ISSDRepository
	{
		private readonly MyDbContext myDbContext;

		public SSDRepository(MyDbContext myDbContext)
		{
			this.myDbContext = myDbContext;
		}
		public async Task<int> AddSSD(SSD sSD)
		{
			myDbContext.SSD.Add(sSD);
			return await myDbContext.SaveChangesAsync();
		}

		public async Task<int> DeleteSSD(int id)
		{
			var SSD=await myDbContext.SSD.FindAsync(id);
			if(SSD != null)
			{
				myDbContext.SSD.Remove(SSD);
				return await myDbContext.SaveChangesAsync();
			}
			return 0;
		}

		public List<SSD> GetSSD()
		{
			using (SqlConnection connection = new SqlConnection("server=.;database=HR;user=sa;pwd=cssl#123;Encrypt=False;"))
			{
				string sql = "select * from [dbo].[SSD] ";
				return connection.Query<SSD>(sql).ToList();
			}
		}
	}
}
